# -*- coding: UTF-8 -*-
import requests
import kuser_agent as kua
import re
import json

content_p:bytes = requests.get(
    url='https://search.51job.com/list/010000,000000,0000,00,9,99,%25E6%2595%25B0%25E6%258D%25AE%25E5%2588%2586%25E6%259E%2590,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=',
    headers = {
        'User-Agent':kua.get()
    }
).content

content:str = content_p.decode(encoding='gbk')
# print(content)

#注意：
# 此处encoding无法解码，可尝试在网页搜索“charset”，查看解码方式
#若更换encoding仍无法解码，可将上述。。。.content（---->结果为bytes）改为使用.text--->结果直接为str


print('window.__SEARCH_RESULT__ =' in content)
json_str = re.findall('window.__SEARCH_RESULT__ = (.*?)</script>',content)[0]
print(json_str)  #----json在线可视化可查看

#把json字符串转成python字典或列表
datas = json.loads(json_str)
print(datas)

for search_result in datas['engine_search_result']:
    print(search_result)

    